package cn.zyjblogs.nio;

import java.nio.ByteBuffer;

/**
 * copyright (C), 2021, 北京同创永益科技发展有限公司
 *
 * @author zhuyijun
 * @version 1.0.0
 * <author>                <time>                  <version>                   <description>
 * zhuyijun         2021/10/8 16:22               1.0
 * @program netty_study
 * @description
 * @create 2021/10/8 16:22
 */
public class ReadOnlyBuffer {
    public static void main(String[] args) {
        //创建buffer
        ByteBuffer buffer = ByteBuffer.allocate(64);
        for (int i = 0; i < 64; i++){
            buffer.put((byte)i);
        }
        //读取
        buffer.flip();

        //得到一个这只读buffer
        ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
        System.out.println(readOnlyBuffer.getClass());

        //读取
        while (readOnlyBuffer.hasRemaining()){
            System.out.println(readOnlyBuffer.get());
        }
    }
}
